{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import required libs\n",
    "import glob\n",
    "import os\n",
    "\n",
    "import tensorflow as tf\n",
    "import tensorflow_model_analysis as tfma\n",
    "print('TF version: {}'.format(tf.version.VERSION))\n",
    "print('TFMA version: {}'.format(tfma.version.VERSION_STRING))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Read artifact information from metadata store.\n",
    "import beam_dag_runner\n",
    "\n",
    "from tfx.orchestration import metadata\n",
    "from tfx.types import standard_artifacts\n",
    "\n",
    "metadata_connection_config = metadata.sqlite_metadata_connection_config(\n",
    "              beam_dag_runner.METADATA_PATH)\n",
    "with metadata.Metadata(metadata_connection_config) as store:\n",
    "    model_eval_artifacts = store.get_artifacts_by_type(standard_artifacts.ModelEvaluation.TYPE_NAME)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# configure output paths\n",
    "# Exact paths to output artifacts can be found in the execution logs\n",
    "# or KFP Web UI if you are using kubeflow.\n",
    "model_eval_path = model_eval_artifacts[-1].uri\n",
    "print(\"Generated model evaluation result:{}\".format(model_eval_path))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Install Jupyter Extensions\n",
    "Note: If running in a local Jupyter notebook, then these Jupyter extensions must be installed in the environment before running Jupyter.\n",
    "\n",
    "```bash\n",
    "jupyter nbextension enable --py widgetsnbextension\n",
    "jupyter nbextension install --py --symlink tensorflow_model_analysis\n",
    "jupyter nbextension enable --py tensorflow_model_analysis\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eval_result = tfma.load_eval_result(model_eval_path)\n",
    "tfma.view.render_slicing_metrics(eval_result, slicing_spec = tfma.slicer.SingleSliceSpec(columns=['trip_start_hour']))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5rc1"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}